home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Controls GH ƒ / utilities.c < prev    next >
C/C++ Source or Header  |  1994-03-04  |  3KB  |  129 lines

  1. #include <GestaltEqu.h>
  2. #include "utilities.h"
  3. /********* CopyRect ********
  4. **** take one rect and copy it to another
  5. **** as this is a useful routine, is small, and
  6. **** is used in a lot of places, I've hand assembled it
  7. **** hopefully, it's as fast as possible *****/
  8. void CopyRect(Rect *src, Rect *dest)
  9. {
  10.     asm 
  11.     {
  12.         MOVE.L    src, A0 // move pointer to src into A0
  13.         MOVE.L    dest, A1 // move pointer to dest into A1
  14.         MOVE.L     (A0)+, (A1)+ // move first point into dest, increment both
  15.         MOVE.L    (A0), (A1) // move second point into dest, no increment
  16.     }
  17. }
  18. /************* Using32Bit *******
  19. ******* calls gestalt to answer the question "are we in 32-bit mode"?
  20. ****** hopefully, the gestalt glue will return an error in systems
  21. ****** before gestalt was available (6.0.4?) ******/
  22. Boolean Using32Bit(void)
  23. {
  24.     long    response;
  25.     OSErr    iErr;
  26.     Boolean    result = FALSE;
  27.     
  28.     iErr = Gestalt(gestaltAddressingModeAttr, &response);
  29.     if (!iErr && (response & 1L))
  30.         result = TRUE;
  31.     return (result);
  32. }
  33. /********** TestForColor *******
  34. ***** answer question "Do we have color quickdraw?" ***/
  35. Boolean TestForColor(void)
  36. {
  37.     SysEnvRec    theSysEnv;
  38.     OSErr        errCode;
  39.     Boolean        result = FALSE;
  40.     errCode = SysEnvirons(curSysEnvVers, &theSysEnv);
  41.     if (!errCode)
  42.     {
  43.         result = theSysEnv.hasColorQD;
  44.     }
  45.     return (result);
  46. /******** UseColorQD *******
  47. **** answer the question, "Is the rectangle completely on
  48. a deep color screen?" *******/
  49. Boolean UseColorQD(ControlHandle me, Rect *theRect)
  50. {
  51.     PrivateHandle    privData;
  52.     Boolean            result = FALSE;
  53.     Rect            myRect, ctlRect;
  54.     Point            origin;
  55.     GDHandle         gd;
  56.     Rect            intersection;
  57.     short            newDepth, flatest = 32;
  58.  
  59.     privData = (PrivateHandle)(*me)->contrlData;
  60.     
  61.     // first check to see if I can check the devices list for the depth of my control
  62.     if (!privData)
  63.         return (FALSE);
  64.     if (!(*privData)->useColorQD)
  65.         return (FALSE);
  66.     if (!(*privData)->devicesAvailable)
  67.         return (FALSE);
  68.         
  69.     CopyRect(theRect, &ctlRect);
  70.     origin.h = ctlRect.left;
  71.     origin.v = ctlRect.top;
  72.     LocalToGlobal(&origin);
  73.     OffsetRect(& ctlRect, origin.h, origin.v);
  74. /******** code provided by Leonard Roesenthol **********/
  75.     gd = GetDeviceList();
  76.     while(gd)
  77.     {    if(SectRect(& ctlRect,&(*gd)->gdRect,&intersection) &&
  78.             TestDeviceAttribute(gd,13) &&     /* screen */
  79.             TestDeviceAttribute(gd,15))        /* active */
  80.         {    newDepth = (*(*gd)->gdPMap)->pixelSize;
  81.             if(newDepth < flatest)
  82.                 flatest = newDepth;
  83.         }
  84.         gd = GetNextDevice(gd);
  85.     }
  86. /****************************************************/
  87.     if (flatest > 4) return (TRUE);
  88.     else return (FALSE);
  89. /* CODE EXAMPLE #1  these trap availables algorithms are from Think Reference*/
  90. #include<Traps.h>
  91. #include<OSUtils.h>
  92.  
  93. #define TrapMask 0x0800
  94.  
  95. short NumToolboxTraps( void )
  96. {
  97.     if (NGetTrapAddress(_InitGraf, ToolTrap) ==
  98.             NGetTrapAddress(0xAA6E, ToolTrap))
  99.         return(0x0200);
  100.     else
  101.         return(0x0400);
  102. }
  103.  
  104. TrapType GetTrapType(short theTrap)
  105. {
  106.  
  107.     if ((theTrap & TrapMask) > 0)
  108.         return(ToolTrap);
  109.     else
  110.         return(OSTrap);
  111.  
  112. }
  113.  
  114. Boolean TrapAvailable(short theTrap)
  115. {
  116.  
  117.     TrapType    tType;
  118.  
  119.     tType = GetTrapType(theTrap);
  120.     if (tType == ToolTrap)
  121.     theTrap = theTrap & 0x07FF;
  122.     if (theTrap >= NumToolboxTraps())
  123.         theTrap = _Unimplemented;
  124.  
  125.     return (NGetTrapAddress(theTrap, tType) !=
  126.             NGetTrapAddress(_Unimplemented, ToolTrap));
  127. }